﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JXT.PrimaryKey.Batman.ObjectConverter
{
    /// <summary>
    /// 对象转换器接口
    /// </summary>
    /// <remarks>
    /// 此接口使用注意对象循环引用
    /// </remarks>
    /// <typeparam name="TSource">原始对象类型</typeparam>
    /// <typeparam name="TResult">目标对象类型</typeparam>
    public interface IConvertable<TSource, TResult>
    {
        /// <summary>
        /// 正向转换器
        /// </summary>
        IObjectConverter<TSource, TResult> Converter { get; }

        /// <summary>
        /// 反向转换接器
        /// </summary>
        IObjectConverter<TResult, TSource> BackConverter { get; }

        /// <summary>
        /// 进行正向转换操作
        /// </summary>
        /// <param name="source">源对象</param>
        /// <returns>目标对象</returns>
        TResult Convert(TSource source);

        /// <summary>
        /// 对集合进行正向转换
        /// </summary>
        /// <param name="sourceEnumerable">源集合</param>
        /// <returns>目标集合</returns>
        IEnumerable<TResult> ConvertEnumerable(IEnumerable<TSource> sourceEnumerable);

        /// <summary>
        /// 进行反向转换操作
        /// </summary>
        /// <param name="result">目标对象</param>
        /// <returns>源对象</returns>
        TSource ConvertBack(TResult result);

        /// <summary>
        /// 对集合进行反向转换
        /// </summary>
        /// <param name="resultEnumerable">目标集合</param>
        /// <returns>源集合</returns>
        IEnumerable<TSource> ConvertBackEnumerable(IEnumerable<TResult> resultEnumerable);
    }
}
